package com.cloud.xiao.controller;

import com.cloud.xiao.service.FeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@DefaultProperties(defaultFallback="fallbackMethod")
public class FeignController {

    @Autowired
    private FeignService feignService;

    @GetMapping(value = "/consumer/getDiscovery/{id}")
    public String getDiscovery(@PathVariable("id") Long id) {
        return feignService.getDiscovery(id);
    }


    @GetMapping(value = "/consumer/ok/{id}")
    public String ok(@PathVariable("id") Long id){
        return feignService.ok(id);
    }

    @GetMapping(value = "/consumer/timeOut/{id}")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value = "1000")
    })
    public String timeOut(@PathVariable("id") Long id) throws Exception{
        return feignService.timeOut(id);
    }

    public String fallbackMethod() throws Exception{
        return "全局服务降级方法";
    }
}
